package com.study.design.model.createPattern.singleton.singletonQuestion;

import java.io.Serializable;

public class Singleton implements Serializable {
	
	private static final long serialVersionUID = -7544209463428254053L;
	
	private static Singleton instance = null ;
	
	private Singleton() {
		//通过手动抛出异常，避免通过反射创建多个单例对象
//		if(instance != null) {
//			throw new RuntimeException() ;
//		}
	}
	
	public static synchronized Singleton getInstance() {
		if(instance == null) {
			instance = new Singleton() ;
		}
		return instance ;
	}
	
	/**
	* @Name: readResolve
	* @Description: 通过定义readResolve()方法，防止反序列化时重新创建对象，从而破坏单例模式
	* @Author: 李超	lc_jack@foxmail.com
	* @Version: V1.0
	* @CreateDate: 2017-2-9 下午8:25:20
	* @Parameters: @return
	* @Parameters: @throws ObjectStreamException
	* @Return: Object
	 */
//	private Object readResolve() throws ObjectStreamException {
//		return instance ;
//	}

}
